﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WebSnapshots
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //var url = "http://www.cnblogs.com/";/Admin/login/PickupGoods?id=2023062040131373
            var url = "http://localhost:32223/Admin/login/PickupGoods?id=2023062040131373";
           // Main(url);
            Bitmap m_Bitmap = WebSnapshotsHelper.GetWebSiteThumbnail(url, 2000, 2000, 500, 500, 750, 0, 60); //宽高根据要获取快照的网页决定
            m_Bitmap.Save("snap_image.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); //图片格式可以自由控制
            m_Bitmap.Dispose();
            System.Diagnostics.Process.Start("snap_image.jpg");
        }

        static void Main(string url)
        {
            try
            {
                WebClient MyWebClient = new WebClient();
                MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据
                Byte[] pageData = MyWebClient.DownloadData(url); //从指定网站下载数据
                string pageHtml = Encoding.Default.GetString(pageData);  //如果获取网站页面采用的是GB2312，则使用这句    
                                                                         //string pageHtml = Encoding.UTF8.GetString(pageData); //如果获取网站页面采用的是UTF-8，则使用这句
                Console.WriteLine(pageHtml);//在控制台输入获取的内容
               
                Console.ReadLine(); //让控制台暂停,否则一闪而过了    
            }
            catch (WebException webEx)
            {
                Console.WriteLine(webEx.Message.ToString());
            }
        }
    }
}
